// import query from '@dfeidao/atom-nodejs/db/query';
import operate from '@dfeidao/atom-nodejs/db/operate';
import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import { productid, systemid } from '../../atom/config';

interface Message {
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
	data: {
		// optional_value_no: string;
		optional_value: string;
		value_description: string;
	};
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:e:\feidao\KaoHe\kh\src\basic-data-wzz\zj-000004\s001,action_id:' + action_id);

	const { exec, update } = operate(action_id, session_id, systemid);
	update('property_optional_values', { productid }, { optional_value: message.data.optional_value, value_description: message.data.value_description });
	const res = await exec();
	// prepare('property_optional_values');
	log('Service end path:e:\feidao\KaoHe\kh\src\basic-data-wzz\zj-000004\s001,action_id:' + action_id);
	return {
		data: res
	};
}
